
<template>
    <div>
        <el-dialog
                :title="title"
                :close-on-click-modal="false"
                v-dialogDrag
                :visible.sync="editVisible"
        >
            <el-form
                    v-loading="loading"
                    label-width="105px"
                    ref="editForm"
                    :model="editForm">

                                            <el-form-item label="输出代号:" prop="codes" :rules="[
                              {required: true, message:'请输入输出代号', trigger:'blur'}
                             ]">
                                <el-input v-model="editForm.codes"></el-input>
                            </el-form-item>
                            <el-form-item label="场景描述:" prop="describes">
                                <el-input type="textarea" row="5" v-model="editForm.describes"></el-input>
                            </el-form-item>
                            <el-form-item label="提示司机:" prop="printDriver" :rules="[
                              {required: true, message:'请输入司机输出语', trigger:'blur'}
                             ]">
                                <el-input type="text"  row="5" v-model="editForm.printDriver"></el-input>
                            </el-form-item>
                            <el-form-item label="提示后台:" prop="printAdmin" :rules="[
                                            {required: true, message:'请输入后台输出语', trigger:'blur'}
                                           ]">
                              <el-input type="text"  row="5" v-model="editForm.printAdmin"></el-input>
                            </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
        <div class="footer-input">
          <el-button size="small" type="primary" @click="doSubmit()" v-noMoreClick
          >确定</el-button
          >
        <el-button size="small" @click="close()">取消</el-button>

        </div>

      </span>
        </el-dialog>
    </div>
</template>
<script>
    import {save, getById} from '@/api/tenant/LedTenant.js'
export default {
      components: {
      },
      data () {
        return {
          loading: false,
          areaLabel: {},
          method: '',
          title: '',
          editForm: {
            id: '',
            codes: '',
            describes: '',
            printAdmin: '',
            printDriver: ''
          },
          editVisible: false,
          detailsVisible: false,
          tableData1: [],
          page: {
            pageSize: 10,
            pageNo: 1,
            total: 0
          },
          props: 1,
          dialogVisible: false,
          query: ''
        }
      },
      methods: {
        select (e) {
          this.editForm.companyName = e.names
          this.editForm.companyId = e.id
          this.dialogVisible = false
          console.log(e)
        },
        init (method, obj) {
          if (method === 'add') {
            this.editVisible = true
            this.$nextTick(() => {
              this.$refs.editForm.resetFields()
                        // this.editForm = {}
            })
            this.editForm.id = ''
            this.editForm.codes = ''
            this.editForm.describes = ''
            this.editForm.printAdmin = ''
            this.editForm.printDriver = ''
            this.title = '新增'
            this.visible = true
            this.loading = false
          } else if (method === 'edit') {
            this.editVisible = true
            this.method = method
            this.title = '修改'
            console.log(obj.id)
            this.$set(this.editForm, 'id', obj.id)
            this.$nextTick(() => {
              this.loading = true
              if (method === 'edit' || method === 'view') { // 修改或者查看
                getById({id: this.editForm.id}).then((res) => {
                  if (res.data.code === '200') {
                    this.editForm = res.data.result
                    this.loading = false
                  } else {
                    this.loading = false
                    this.visible = false
                    this.$message({
                      type: 'error',
                      message: res.data.message
                    })
                  }
                })
              }
            })
            this.visible = true
            this.loading = false
          }
        },
        close () {
          this.editVisible = false
        },
        doSubmit () {
          this.$refs['editForm'].validate((valid) => {
            if (valid) {
              save(this.editForm).then((res) => {
                if (res.data.code === '200') {
                  this.$message({
                    message: '编辑成功',
                    type: 'success'
                  })
                  this.editVisible = false
                  this.$emit('refreshDataList')
                }
              })
            }
          })
        }
      },
      mounted () {

      }
    }
</script>
<style lang="scss" scoped>
    ::v-deep .el-dialog{
    .el-form{
    .el-input__inner{
        width: 320px;
    }
    .inputAppend-wrapper{
    .el-input__inner{
        width: 282px;
    }
    }
    }
    }
</style>
